package com.zmj.controller;

import com.zmj.service.ListService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.redis.core.RedisTemplate;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import java.util.ArrayList;
import java.util.List;

@Controller
public class ListController {

    @Autowired
    RedisTemplate<String,String> redisTemplate;

    @Autowired
    ListService listService;

    @RequestMapping("/list")
    @ResponseBody
    public List getList(){
        listService.getNews();
        List<String> list=  redisTemplate.opsForList().range("news:top5",0,4);
        return list;
    }

    @RequestMapping("/add")
    @ResponseBody
    public List addList(){
        listService.addNews();
        List<String> list=  redisTemplate.opsForList().range("news:top5",0,4);
        return list;
    }


}
